package com.yeyaomai.dksns.flowis.service.result;

import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.Set;
import com.yeyaomai.dksns.flowis.domain.TrendAnalysisDay;
import com.yeyaomai.dksns.flowis.domain.TrendAnalysisHour;
import com.yeyaomai.dksns.flowis.util.Globals;
import com.yeyaomai.dksns.flowis.util.VelocityToolDateUtils;

/**
 * 生成动态XMl类
 * 
 * @author xiaqin
 * 
 */
public class DynamicXml {

	/**
	 * 拼装柱状图
	 * 
	 * @param value
	 * @return
	 */
	public static String getColumn(String value) {
		String[] values = value.split("\\|");
		String[] trendnu = values[0].split(",");

		long[] trendnumber = new long[24];
		int n;
		for (n = 0; n < trendnu.length; n++) {
			trendnumber[n] = Long.valueOf(trendnu[n]);
		}

		long min = trendnumber[0];
		long max = trendnumber[0];
		int maxtime = 0;
		int mintime = 0;
		int m;
		for (m = 0; m < trendnumber.length; m++) {
			if (max < trendnumber[m]) {
				max = trendnumber[m];
				maxtime = m;
			}
			if (min > trendnumber[m] && trendnumber[m] > 0) {
				min = trendnumber[m];
				mintime = m;
			}
		}
		String type = values[1];
		if (type.equals("UV")) {
			type = "独立访客";
		}
		if (type.equals("NUV")) {
			type = "新独立访客";
		}

		String xml = "";
		xml = "<chart showFCMenuItem='0' palette='2'caption='最大值 [" + maxtime + ":00]  " + max + "   最小值[" + mintime
				+ ":00]  " + min + " ' canvasBorderAlpha='20'"
				+ "bgColor='FFFFFF' unescapeLinks='0' canvasBorderThickness='1' showBorder='0'"
				+ "legendBorderAlpha='0' bgAngle='360' showlegend='1' showValues='1'"
				+ "decimals='2' useRoundEdges='0' baseFontSize='9' outCnvbaseFontSize='10'"
				+ "use3DLighting='0' numberScaleValue='10000,1,1,1000' formatNumberScale='1'"
				+ "numberScaleUnit=' , ,万,千万 ' toolTipSepChar='：  ' plotFillRatio=''"
				+ "chartRightMargin='6' chartTopMargin='0' chartLeftMargin='0'"
				+ "chartBottomMargin='3' showShadow='0' labelStep='2' animation='0'>";
		int a;
		for (a = 0; a < 24; a++) {
			xml += "<set label='" + a + ":00' value='" + trendnumber[a] + "' toolText='" + type + ": " + trendnumber[a]
					+ "' />";
		}

		xml += "<styles><definition><style name='CaptionFont' type='font' size='12' /></definition>"
				+ "<application><apply toObject='caption' styles='CaptionFont' /></application></styles></chart>";
		return xml;
	}

	/**
	 * 
	 * @param trendAnalysisDayList
	 * @param end
	 * @param keys
	 *            分别是pv,ip,uv,newuser
	 * @return
	 */
	// 最近30天月统计
	public static String getLine30(List<TrendAnalysisDay> trendAnalysisDayList, String end, String keys) {

		String pv = "<dataset  seriesName='PV' color='0033CC' anchorBorderColor='0033CC'  >";
		String ip = "<dataset  seriesName='IP' color='FF0000' anchorBorderColor='FF0000'  >";
		String uv = "<dataset  seriesName='独立访客' color='33CC33' anchorBorderColor='33CC33'  >";
		String nuv = "<dataset  seriesName='新独立访客' color='#ffa902' anchorBorderColor='#ffa902'  >";
		String tail = "<styles><definition><style name='CaptionFont' type='font' size='12'  /><style name='myLegendFont' type='font' size='11'  /></definition><application><apply toObject='CAPTION' styles='CaptionFont'  /><apply toObject='SUBCAPTION' styles='CaptionFont'  /><apply toObject='Legend' styles='myLegendFont'  /></application></styles></chart>";

		StringBuffer xml = new StringBuffer();
		xml.append("<chart showFCMenuItem='0' lineThickness='2' showValues='0' anchorRadius='4' divLineAlpha='20' divLineColor='CC3300' divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='5' alternateHGridColor='CC3300' shadowAlpha='40' labelStep='5' numvdivlines='28' showAlternateVGridColor='1' chartsshowShadow='1' chartRightMargin='35' chartTopMargin='15' chartLeftMargin='10' chartBottomMargin='3' bgColor='FFFFFF' canvasBorderThickness='1' showBorder='0' legendBorderAlpha='0' bgAngle='360' showlegend='0' borderColor='DEF3F3' toolTipBorderColor='cccc99' canvasPadding='0' toolTipBgColor='ffffcc' legendShadow='0' baseFontSize='12' canvasBorderAlpha='20' outCnvbaseFontSize='10' outCnvbaseFontColor='000000' numberScaleValue='10000,1,1,1000' formatNumberScale='1' palette='2' numberScaleUnit=' , ,万,千万' lineColor='AFD8F8'  ><categories  >");
		String[] dateRetStr = VelocityToolDateUtils.getSpecifiedContinusDays(null, end, 30, null, Globals.CONDITION_A)
				.split(",");
		String[] dateRetStrb = VelocityToolDateUtils.getSpecifiedContinusDays(null, end, 30, Globals.DATE_FORMAT_B,
				Globals.CONDITION_A).split(",");
		for (int i = 0; i < dateRetStr.length; i++) {

			xml.append("<category label='");
			xml.append(dateRetStr[i]);
			xml.append("'  />");

		}
		xml.append("</categories>");

		Map<String, String> dateMap = Collections.synchronizedMap(new TreeMap<String, String>());
		Map<String, TrendAnalysisDay> objectMap = new HashMap<String, TrendAnalysisDay>();

		for (TrendAnalysisDay day : trendAnalysisDayList) {
			objectMap.put(Globals.FORMAT_TYPE_A.format(day.getTrendDay()), day);
		}

		// if exists
		if (keys.indexOf("pv") != -1) {
			xml.append(pv);
			// 拼成原始串
			for (int i = 0; i < dateRetStrb.length; i++) {
				dateMap.put(dateRetStrb[i], "<set  value='0' toolText='PV: 0 " + dateRetStr[i] + "'  />");
			}

			for (Entry<String, String> entry : dateMap.entrySet()) {
				String key = entry.getKey();
				if (objectMap.containsKey(key)) {
					String dataValue = entry.getValue();
					TrendAnalysisDay day = objectMap.get(key);
					String newValue = dataValue.replace("value='0' toolText='PV: 0", "value='" + day.getPageView()
							+ "'toolText='PV: " + day.getPageView());
					// 渲染
					dateMap.put(key, newValue);
				}
			}
			xml.append(handleMap(dateMap));
			// clear
			dateMap.clear();
			xml.append("</dataset>");
		}
		if (keys.indexOf("ip") != -1) {
			xml.append(ip);

			for (int i = 0; i < dateRetStrb.length; i++) {
				dateMap.put(dateRetStrb[i], "<set  value='0' toolText='IP: 0 " + dateRetStr[i] + "'  />");
			}

			for (Entry<String, String> entry : dateMap.entrySet()) {
				String key = entry.getKey();
				if (objectMap.containsKey(key)) {
					String dataValue = entry.getValue();
					TrendAnalysisDay day = objectMap.get(key);
					String newValue = dataValue.replace("value='0' toolText='IP: 0", "value='" + day.getIp()
							+ "'toolText='IP: " + day.getIp());
					// 渲染
					dateMap.put(key, newValue);
				}
			}
			xml.append(handleMap(dateMap));
			dateMap.clear();

			xml.append("</dataset>");

		}
		if (keys.indexOf("uv") != -1) {

			xml.append(uv);
			for (int i = 0; i < dateRetStrb.length; i++) {
				dateMap.put(dateRetStrb[i], "<set  value='0' toolText='独立访客: 0 " + dateRetStr[i] + "'  />");
			}
			for (Entry<String, String> entry : dateMap.entrySet()) {
				String key = entry.getKey();
				if (objectMap.containsKey(key)) {
					String dataValue = entry.getValue();
					TrendAnalysisDay day = objectMap.get(key);
					String newValue = dataValue.replace("value='0' toolText='独立访客: 0", "value='" + day.getUniqueHost()
							+ "'toolText='独立访客: " + day.getUniqueHost());
					// 渲染
					dateMap.put(key, newValue);
				}
			}
			xml.append(handleMap(dateMap));
			dateMap.clear();
			xml.append("</dataset>");
		}
		if (keys.indexOf("newuser") != -1) {
			xml.append(nuv);
			for (int i = 0; i < dateRetStrb.length; i++) {
				dateMap.put(dateRetStrb[i], "<set  value='0' toolText='新独立访客: 0 " + dateRetStr[i] + "'  />");
			}
			for (Entry<String, String> entry : dateMap.entrySet()) {
				String key = entry.getKey();
				if (objectMap.containsKey(key)) {
					String dataValue = entry.getValue();
					TrendAnalysisDay day = objectMap.get(key);
					String newValue = dataValue.replace("value='0' toolText='新独立访客: 0",
							"value='" + day.getNewUniqueHost() + "'toolText='新独立访客: " + day.getNewUniqueHost());
					// 渲染
					dateMap.put(key, newValue);
				}
			}
			xml.append(handleMap(dateMap));
			dateMap.clear();
			xml.append("</dataset>");
		}
		xml.append(tail);
		System.out.println(xml.toString());
		return xml.toString();
	}
	//本月统计拼串
	public static String getLinetoMonth(List<TrendAnalysisDay> trendAnalysisDayList, String start,String end, String keys) {

		String pv = "<dataset  seriesName='PV' color='0033CC' anchorBorderColor='0033CC'  >";
		String ip = "<dataset  seriesName='IP' color='FF0000' anchorBorderColor='FF0000'  >";
		String uv = "<dataset  seriesName='独立访客' color='33CC33' anchorBorderColor='33CC33'  >";
		String nuv = "<dataset  seriesName='新独立访客' color='#ffa902' anchorBorderColor='#ffa902'  >";
		String tail = "<styles><definition><style name='CaptionFont' type='font' size='12'  /><style name='myLegendFont' type='font' size='11'  /></definition><application><apply toObject='CAPTION' styles='CaptionFont'  /><apply toObject='SUBCAPTION' styles='CaptionFont'  /><apply toObject='Legend' styles='myLegendFont'  /></application></styles></chart>";

		StringBuffer xml = new StringBuffer();
		xml.append("<chart showFCMenuItem='0' lineThickness='2' showValues='0' anchorRadius='4' divLineAlpha='20' divLineColor='CC3300' divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='5' alternateHGridColor='CC3300' shadowAlpha='40' labelStep='5' numvdivlines='28' showAlternateVGridColor='1' chartsshowShadow='1' chartRightMargin='35' chartTopMargin='15' chartLeftMargin='10' chartBottomMargin='3' bgColor='FFFFFF' canvasBorderThickness='1' showBorder='0' legendBorderAlpha='0' bgAngle='360' showlegend='0' borderColor='DEF3F3' toolTipBorderColor='cccc99' canvasPadding='0' toolTipBgColor='ffffcc' legendShadow='0' baseFontSize='12' canvasBorderAlpha='20' outCnvbaseFontSize='10' outCnvbaseFontColor='000000' numberScaleValue='10000,1,1,1000' formatNumberScale='1' palette='2' numberScaleUnit=' , ,万,千万' lineColor='AFD8F8'  ><categories  >");
		String[] dateRetStr = VelocityToolDateUtils.getSpecifiedContinusDays(start, end, 30, null, Globals.CONDITION_B)
				.split(",");
		String[] dateRetStrb = VelocityToolDateUtils.getSpecifiedContinusDays(start, end, 30, Globals.DATE_FORMAT_B,
				Globals.CONDITION_B).split(",");
		for (int i = 0; i < dateRetStr.length; i++) {

			xml.append("<category label='");
			xml.append(dateRetStr[i]);
			xml.append("'  />");

		}
		xml.append("</categories>");

		Map<String, String> dateMap = Collections.synchronizedMap(new TreeMap<String, String>());
		Map<String, TrendAnalysisDay> objectMap = new HashMap<String, TrendAnalysisDay>();

		for (TrendAnalysisDay day : trendAnalysisDayList) {
			objectMap.put(Globals.FORMAT_TYPE_A.format(day.getTrendDay()), day);
		}

		// if exists
		if (keys.indexOf("pv") != -1) {
			xml.append(pv);
			// 拼成原始串
			for (int i = 0; i < dateRetStrb.length; i++) {
				dateMap.put(dateRetStrb[i], "<set  value='0' toolText='PV: 0 " + dateRetStr[i] + "'  />");
			}

			for (Entry<String, String> entry : dateMap.entrySet()) {
				String key = entry.getKey();
				if (objectMap.containsKey(key)) {
					String dataValue = entry.getValue();
					TrendAnalysisDay day = objectMap.get(key);
					String newValue = dataValue.replace("value='0' toolText='PV: 0", "value='" + day.getPageView()
							+ "'toolText='PV: " + day.getPageView());
					// 渲染
					dateMap.put(key, newValue);
				}
			}
			xml.append(handleMap(dateMap));
			// clear
			dateMap.clear();
			xml.append("</dataset>");
		}
		if (keys.indexOf("ip") != -1) {
			xml.append(ip);

			for (int i = 0; i < dateRetStrb.length; i++) {
				dateMap.put(dateRetStrb[i], "<set  value='0' toolText='IP: 0 " + dateRetStr[i] + "'  />");
			}

			for (Entry<String, String> entry : dateMap.entrySet()) {
				String key = entry.getKey();
				if (objectMap.containsKey(key)) {
					String dataValue = entry.getValue();
					TrendAnalysisDay day = objectMap.get(key);
					String newValue = dataValue.replace("value='0' toolText='IP: 0", "value='" + day.getIp()
							+ "'toolText='IP: " + day.getIp());
					// 渲染
					dateMap.put(key, newValue);
				}
			}
			xml.append(handleMap(dateMap));
			dateMap.clear();

			xml.append("</dataset>");

		}
		if (keys.indexOf("uv") != -1) {

			xml.append(uv);
			for (int i = 0; i < dateRetStrb.length; i++) {
				dateMap.put(dateRetStrb[i], "<set  value='0' toolText='独立访客: 0 " + dateRetStr[i] + "'  />");
			}
			for (Entry<String, String> entry : dateMap.entrySet()) {
				String key = entry.getKey();
				if (objectMap.containsKey(key)) {
					String dataValue = entry.getValue();
					TrendAnalysisDay day = objectMap.get(key);
					String newValue = dataValue.replace("value='0' toolText='独立访客: 0", "value='" + day.getUniqueHost()
							+ "'toolText='独立访客: " + day.getUniqueHost());
					// 渲染
					dateMap.put(key, newValue);
				}
			}
			xml.append(handleMap(dateMap));
			dateMap.clear();
			xml.append("</dataset>");
		}
		if (keys.indexOf("newuser") != -1) {
			xml.append(nuv);
			for (int i = 0; i < dateRetStrb.length; i++) {
				dateMap.put(dateRetStrb[i], "<set  value='0' toolText='新独立访客: 0 " + dateRetStr[i] + "'  />");
			}
			for (Entry<String, String> entry : dateMap.entrySet()) {
				String key = entry.getKey();
				if (objectMap.containsKey(key)) {
					String dataValue = entry.getValue();
					TrendAnalysisDay day = objectMap.get(key);
					String newValue = dataValue.replace("value='0' toolText='新独立访客: 0",
							"value='" + day.getNewUniqueHost() + "'toolText='新独立访客: " + day.getNewUniqueHost());
					// 渲染
					dateMap.put(key, newValue);
				}
			}
			xml.append(handleMap(dateMap));
			dateMap.clear();
			xml.append("</dataset>");
		}
		xml.append(tail);
		System.out.println(xml.toString());
		return xml.toString();
	}
	
	// 对map拼串
	private static String handleMap(Map<String, String> map) {
		if (!(null != map && map.size() > 0))
			return null;
		StringBuffer sb = new StringBuffer();

		for (Entry<String, String> entry : map.entrySet()) {
			sb.append(entry.getValue());
		}
		return sb.toString();
	}
	/*
	 * 拼拆线图
	 * 
	 * @param beforehours
	 * @param todayhours
	 * @param keyid
	 * @return
	 */
	public static String getLine(List<TrendAnalysisHour> beforehours,
			List<TrendAnalysisHour> todayhours, String keyid,String todate,String beforedate) {

		String type[] = keyid.split(",");
		StringBuffer xml = new StringBuffer(
				"<chart showFCMenuItem='0' lineThickness='2' showValues='0' anchorRadius='4' divLineAlpha='20' divLineColor='CC3300' divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='5' alternateHGridColor='CC3300' shadowAlpha='40' labelStep='2' numvdivlines='22' showAlternateVGridColor='1' chartsshowShadow='1' chartRightMargin='6' chartTopMargin='15' chartLeftMargin='10' chartBottomMargin='3' bgColor='FFFFFF' canvasBorderThickness='1' showBorder='0' legendBorderAlpha='0' bgAngle='360' showlegend='0' borderColor='DEF3F3' toolTipBorderColor='cccc99' canvasPadding='0' toolTipBgColor='ffffcc' legendShadow='0' baseFontSize='12' canvasBorderAlpha='20' outCnvbaseFontSize='10' outCnvbaseFontColor='000000' numberScaleValue='10000,1,1,1000' formatNumberScale='1' palette='2' numberScaleUnit=' , ,万,千万' lineColor='AFD8F8'  ><categories >");
		StringBuffer pvtoxml = new StringBuffer(
				"<dataset  seriesName='PV' color='0033CC' anchorBorderColor='0033CC'>");
		StringBuffer pvbeforexml = new StringBuffer(
				"<dataset  seriesName='PV' color='6699FF' anchorBorderColor='6699FF'>");
		StringBuffer uvtoxml = new StringBuffer(
				"<dataset  seriesName='独立访客' color='33CC33' anchorBorderColor='33CC33'>");
		StringBuffer uvbeforexml = new StringBuffer(
				"<dataset  seriesName='独立访客' color='99FF99' anchorBorderColor='99FF99'>");
		StringBuffer iptoxml = new StringBuffer(
				"<dataset  seriesName='IP' color='FF0000' anchorBorderColor='FF0000'>");
		StringBuffer ipbeforexml = new StringBuffer(
				"<dataset  seriesName='IP' color='FF9999' anchorBorderColor='FF9999'>");
		StringBuffer newuvtoxml = new StringBuffer(
				"<dataset  seriesName='新独立访客' color='ffa902' anchorBorderColor='ffa902'>");
		StringBuffer newuvbeforexml = new StringBuffer(
				"<dataset  seriesName='新独立访客' color='f0ff02' anchorBorderColor='f0ff02'>");

		for (int i = 0; i < 24; i++) {
			if (i >= 10) {
				xml.append("<category label='" + i + ":00'  />");
			} else {
				xml.append("<category label='0" + i + ":00'  />");
			}
		}
		xml.append("</categories>");

		Map<String, TrendAnalysisHour> beforemap = new HashMap<String, TrendAnalysisHour>(
				32);
		Map<String, TrendAnalysisHour> tomap = new HashMap<String, TrendAnalysisHour>(
				32);

		for (TrendAnalysisHour before : beforehours) {
			beforemap.put(before.getHour(), before);
		}
		for (TrendAnalysisHour today : todayhours) {
			tomap.put(today.getHour(), today);
		}
		Map<String,String> typemap= new HashMap<String, String>();
		for (int y = 0; y < type.length; y++) {
			typemap.put(type[y], type[y]);
		}
		Map<String, String> map = new TreeMap<String, String>();
		String key = "";
		for (int x = 0; x < 24; x++) {

			if (x < 10) {
				key = "0" + x + ":00";
			} else {
				key = x + ":00";
			}
			map.put(key, "<set  value='0' toolText='PV:0 0 0'/>");
		}
		Set<String> keys = map.keySet();
		String pv = typemap.get("pv");
		String uv = typemap.get("uv");
		String ip = typemap.get("ip");
		String newuser = typemap.get("newuser");
		for (Iterator<String> it = keys.iterator(); it.hasNext();) {
			String value = it.next();
			TrendAnalysisHour maptovalue = tomap.get(value);
			TrendAnalysisHour mapbeforevalue = beforemap.get(value);
			if(!(null == pv))
			{
				
				if(null == maptovalue)
				pvtoxml.append("<set  value='0' toolText='PV:0 "+todate+" "+value+"'/>");
				else
					pvtoxml.append("<set  value='" + maptovalue.getPageView()
							+ "' toolText='PV:" + maptovalue.getPageView() + " "
							+ maptovalue.getTrendDay() + " " + maptovalue.getHour()
							+ "'/>");
				if(null == mapbeforevalue)
				pvbeforexml.append("<set  value='0' toolText='PV:0 "+beforedate+" "+value+"'/>");
				else
					pvbeforexml.append("<set  value='" + mapbeforevalue.getPageView()
							+ "' toolText='PV:" + mapbeforevalue.getPageView() + " "
							+ mapbeforevalue.getTrendDay() + " " + mapbeforevalue.getHour()
							+ "'/>");
			}
			if(!(null == uv))
			{
				if(null == maptovalue)
					uvtoxml.append("<set  value='0' toolText='独立访客:0 "+todate+" "+value+"'/>");
				else
					uvtoxml.append("<set  value='" + maptovalue.getUniqueHost()
							+ "' toolText='独立访客:" + maptovalue.getUniqueHost() + " "
							+ maptovalue.getTrendDay() + " " + maptovalue.getHour()
							+ "'/>");
				if(null == mapbeforevalue)
					uvbeforexml.append("<set  value='0' toolText='独立访客:0 "+beforedate+" "+value+"'/>");
				else
					uvbeforexml.append("<set  value='" + mapbeforevalue.getUniqueHost()
							+ "' toolText='独立访客:" + mapbeforevalue.getUniqueHost() + " "
							+ mapbeforevalue.getTrendDay() + " " + mapbeforevalue.getHour()
							+ "'/>");
			}
			if(!(null == ip))
			{
				if(null == maptovalue)
					iptoxml.append("<set  value='0' toolText='IP:0 "+todate+" "+value+"'/>");
				else
					iptoxml.append("<set  value='" + maptovalue.getIp()
							+ "' toolText='IP:" + maptovalue.getIp() + " "
							+ maptovalue.getTrendDay() + " " + maptovalue.getHour()
							+ "'/>");
				if(null == mapbeforevalue)
					ipbeforexml.append("<set  value='0' toolText='IP:0 "+beforedate+" "+value+"'/>");
				else
					ipbeforexml.append("<set  value='" + mapbeforevalue.getIp()
							+ "' toolText='IP:" + mapbeforevalue.getIp() + " "
							+ mapbeforevalue.getTrendDay() + " " + mapbeforevalue.getHour()
							+ "'/>");
			}
			if(!(null == newuser))
			{
				if(null == maptovalue)
					newuvtoxml.append("<set  value='0' toolText='新独立访客:0 "+todate+" "+value+"'/>");
				else
					newuvtoxml.append("<set  value='" + maptovalue.getNewUniqueHost()
							+ "' toolText='新独立访客:" + maptovalue.getNewUniqueHost() + " "
							+ maptovalue.getTrendDay() + " " + maptovalue.getHour()
							+ "'/>");
				if(null == mapbeforevalue)
					newuvbeforexml.append("<set  value='0' toolText='新独立访客:0 "+beforedate+" "+value+"'/>");
				else
					newuvbeforexml.append("<set  value='" + mapbeforevalue.getNewUniqueHost()
							+ "' toolText='新独立访客:" + mapbeforevalue.getNewUniqueHost() + " "
							+ mapbeforevalue.getTrendDay() + " " + mapbeforevalue.getHour()
							+ "'/>");
			}
		}
		pvtoxml.append("</dataset>");
		pvbeforexml.append("</dataset>");
		uvtoxml.append("</dataset>");
		uvbeforexml.append("</dataset>");
		iptoxml.append("</dataset>");
		ipbeforexml.append("</dataset>");
		newuvtoxml.append("</dataset>");
		newuvbeforexml.append("</dataset>");
		xml.append(pvtoxml).append(pvbeforexml).append(uvtoxml).append(uvbeforexml).append(iptoxml).append(ipbeforexml).append(newuvtoxml).append(newuvbeforexml);
		xml.append("<styles><definition><style name='CaptionFont' type='font' size='12'  /><style name='myLegendFont' type='font' size='11'  /></definition><application><apply toObject='CAPTION' styles='CaptionFont'  /><apply toObject='SUBCAPTION' styles='CaptionFont'  /><apply toObject='Legend' styles='myLegendFont'  /></application></styles></chart>");
		return xml.toString();
	}
	
	/*
	 * 拼饼状图
	 * 
	 * @param referDomain域名总汇
	 * @param beforeDate开始日期
	 * @param toDate结束日期
	 * @return
	 */
	public static String getpie(Map<String,String> referDomain,String beforeDate,String toDate)
	{
		StringBuffer xml = new StringBuffer("<chart showFCMenuItem='0' toolTipSepChar=': ' numberScaleUnit=' , ,万,千万' formatNumberScale='1' numberScaleValue='10000,1,1,1000' palette='4' bgColor='666666' showPercentageValues='0' use3DLighting='1' chartsshowShadow='0' subcaption='");
		xml.append(beforeDate).append(" - ");
		xml.append(toDate).append("' caption='来路域名-按来访次数查询' showShadow='0' bgAlpha='0' baseFontSize='12' baseFontColor='000000' bgAngle='360' showBorder='0' pieRadius='90'  >");
		for (Iterator<String> iterator = referDomain.keySet().iterator(); iterator.hasNext();) {
			String key = (String) iterator.next();
			String value = referDomain.get(key);
			xml.append("<set  value='"+value+"' label='"+key+"'  />");
		}
		xml.append("<styles><definition><style name='CaptionFont' type='font' bold='0' size='12'  /></definition><application><apply toObject='subcaption' styles='CaptionFont'  /></application></styles></chart>");
		return xml.toString();
	}
}
